﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;

namespace DevCore.Web
{
    /// <summary>
    /// Session相关操作信息
    /// </summary>
    public class SessionHelper
    {
        /// <summary>
        /// 设置Session值
        /// </summary>
        /// <param name="name">Session名称</param>
        /// <param name="value">Session值</param>
        /// <returns>返回是否设置成功</returns>
        public static Boolean Set(String name, object value)
        {
            Boolean retValue = false;
            if(HttpContext.Current != null && HttpContext.Current.Session != null)
            {
                HttpContext.Current.Session[name] = value;
                retValue = true;
            }
            return retValue;
        }

        /// <summary>
        /// 移除一个Session
        /// </summary>
        /// <param name="name">Session的名称</param>
        public static void Remove(String name)
        {
            if (HttpContext.Current != null && HttpContext.Current.Session != null)
            {
                HttpContext.Current.Session.Remove(name);
            }
        }

        /// <summary>
        /// 得到Session的值
        /// </summary>
        /// <param name="name">Session名称</param>
        /// <returns>Session值</returns>
        public static object Get(String name)
        {
            if (HttpContext.Current != null && HttpContext.Current.Session != null)
            {
               return HttpContext.Current.Session[name];
            }
            return null;
        }

        /// <summary>
        /// 清空所有的Session
        /// </summary>
        public static void Clear()
        {
            if (HttpContext.Current != null && HttpContext.Current.Session != null)
            {
                HttpContext.Current.Session.Clear();
            }
        }




    }
}
